package cn.zjutleo.village_server.config;

import cn.zjutleo.village_server.interceptor.UserLoginInterceptor;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: 张坤
 * @DateTime: 2021/8/26 11:38
 * @Description: 该类用于 TODO
 */
@SpringBootConfiguration
public class UserLoginConfigurer implements WebMvcConfigurer {
    @Bean
    public UserLoginInterceptor getLoginIntercepter() {
        return new UserLoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        //对所有路径应用拦截器，除了 /index.html
        registry.addInterceptor(getLoginIntercepter()).addPathPatterns("/**").excludePathPatterns("/index.html");
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //设置访问项目外文件路径
        registry.addResourceHandler("/api/file/**").addResourceLocations("file:" + "d:/desktop/img/");
    }

}
